multistage graph problem